package com.lear.mypush;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.util.Log;

public class StartupService extends Service {

	private SharedPreferences mPrefs;
	private String mDeviceID;
	private Context mContext;

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

	public class PushThread extends Thread {
		public void run() {
			Log.e("HOME", "Push thread...");
			try {
				Thread.sleep(30 * 1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			PushService.actionStart(mContext);
		}
	}

	@Override
	public void onCreate() {
		super.onCreate();
		Log.e("HOME", "On create in service!");
		mContext = getApplicationContext();
		mPrefs = getSharedPreferences("LearPushPrefs", MODE_PRIVATE);
		mPrefs.edit().putBoolean(PushService.PREF_STARTED, false).commit();

		mDeviceID = mPrefs.getString(PushService.PREF_DEVICE_ID, "client"
				+ (int) (Math.random() * 100));
		mPrefs.edit().putString(PushService.PREF_DEVICE_ID, mDeviceID).commit();
		new PushThread().start();
	}

}
